﻿using Abide_AddOn_API;
using System;
using System.Windows.Forms;

namespace Abide.Controls
{
    public partial class TypeElement : UserControl
    {
        public RegistrationType Registration
        {
            get { return registerRad.Checked ? RegistrationType.Register : RegistrationType.Unregister; }
        }
        private FileAssociation association;
        public FileAssociation Association
        {
            get { return association; }
            set { association = value; OnAssociationChanged(new EventArgs()); }
        }

        public TypeElement()
        {
            InitializeComponent();
        }
        protected virtual void OnAssociationChanged(EventArgs e)
        {
            //Set Labels
            extLabel.Text = "*." + association.FileExtension;
            progIdLabel.Text = string.Format("(Abide Type.{0}) {1}", association.FileExtension, association.TypeDescription);

            //Check in appropriate boxes
            unregisterRad.Checked = Classes.Registration.TypeRegistered(association);
            registerRad.Checked = !Classes.Registration.TypeRegistered(association);

            //Prevent error by disabling unregister if type isn't registered
            unregisterRad.Enabled = Classes.Registration.TypeRegistered(association);
        }
    }
    public enum RegistrationType
    {
        Register,
        Unregister
    }
}
